home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MCASM.RAR / MC_ASM.EXE / WROX_ASM / CH9 / UNERASE / GET.ASM next >
Assembly Source File  |  1994-05-22  |  4KB  |  193 lines

  1. MODEL SMALL
  2. .386
  3.  
  4. PUBLIC    get_boot
  5. PUBLIC    get_sector
  6. PUBLIC    set_sector
  7. PUBLIC    get_root
  8.  
  9. .CODE
  10.  
  11. i25startsec    dd    ?
  12. i25countsec    dw    ?
  13. i25off        dw    ?
  14. i25seg        dw    ?
  15.  
  16. get_boot    PROC    C FAR
  17.         ARG    drive:byte
  18.         LOCAL    addr1:word
  19.         USES    cx,dx,ds
  20.  
  21.         mov    ah,48h        ; Allocate memory for boot sector
  22.         mov    bx,32
  23.         int    21h
  24.         jc    @@get_boot_err
  25.  
  26.         mov    addr1,ax
  27.         mov    ds,ax
  28.         xor    bx,bx
  29.         mov    al,drive
  30.         mov    cx,1
  31.         xor    dx,dx
  32.         int    25h        ; Read boot sector
  33.         pop    dx
  34.         jnc    @@get_boot_010
  35. ; Disk is larger than 32 Mbytes.
  36.         mov    word ptr i25startsec,0
  37.         mov    word ptr i25startsec+2,0
  38.         mov    i25countsec,1
  39.         mov    i25off,0
  40.         mov    i25seg,ds
  41.         mov    al,drive
  42.         mov    cx,0ffffh
  43.         push    cs
  44.         pop    ds
  45.         lea    bx,i25startsec
  46.         int    25h        ; Read boot sector
  47.         pop    dx
  48.         jc    @@get_boot_err
  49. @@get_boot_010:    xor    ax,ax
  50.         mov    bx,addr1
  51.         ret
  52. @@get_boot_err:    mov    ax,-1
  53.         ret
  54. get_boot    ENDP
  55.  
  56. get_sector    PROC    C FAR
  57.         ARG    drive:byte,sector:dword,addr:dword,count:word
  58.         USES    bx,cx,dx,di,si,ds
  59.         mov    ds,word ptr addr+2
  60.         mov    bx,word ptr addr
  61.         mov    dx,word ptr sector
  62.         mov    cx,count
  63.         mov    al,drive
  64.         int    25h
  65.         pop    dx
  66.         jnc    @@get_sec_010
  67. ; Disk is larger than 32 Mbytes.
  68.         mov    ax,word ptr sector
  69.         mov    word ptr i25startsec,ax
  70.         mov    ax,word ptr sector+2
  71.         mov    word ptr i25startsec+2,ax
  72.         mov    ax,count
  73.         mov    i25countsec,ax
  74.         mov    ax,word ptr addr
  75.         mov    i25off,ax
  76.         mov    i25seg,ds
  77.         mov    al,drive
  78.         mov    cx,0ffffh
  79.         push    cs
  80.         pop    ds
  81.         lea    bx,i25startsec
  82.         int    25h
  83.         pop    dx
  84.         jc    @@get_boot_err
  85. @@get_sec_010:    xor    ax,ax
  86.         ret
  87. @@get_sec_err:    mov    ax,-1
  88.         ret
  89. get_sector    ENDP
  90.  
  91. set_sector    PROC    C FAR
  92.         ARG    drive:byte,sector:dword,addr:dword,count:word
  93.         USES    bx,cx,dx,di,si,ds
  94.         mov    ds,word ptr addr+2
  95.         mov    bx,word ptr addr
  96.         mov    dx,word ptr sector
  97.         mov    cx,count
  98.         mov    al,drive
  99.         int    26h
  100.         pop    dx
  101.         jnc    @@set_sec_010
  102. ; Disk is larger than 32 Mbytes.
  103.         mov    ax,word ptr sector
  104.         mov    word ptr i25startsec,ax
  105.         mov    ax,word ptr sector+2
  106.         mov    word ptr i25startsec+2,ax
  107.         mov    ax,count
  108.         mov    i25countsec,ax
  109.         mov    ax,word ptr addr
  110.         mov    i25off,ax
  111.         mov    i25seg,ds
  112.         mov    al,drive
  113.         mov    cx,0ffffh
  114.         push    cs
  115.         pop    ds
  116.         lea    bx,i25startsec
  117.         int    26h
  118.         pop    dx
  119.         jc    @@get_boot_err
  120. @@set_sec_010:    xor    ax,ax
  121.         ret
  122. @@set_sec_err:    mov    ax,-1
  123.         ret
  124. set_sector    ENDP
  125.  
  126. get_root    PROC    C FAR
  127.         ARG    drive:byte,addr:dword
  128.         LOCAL    addr1:word,startsector:word
  129.         USES    cx,dx,ds
  130.  
  131.         mov    ax,word ptr addr+2
  132.         mov    ds,ax
  133.         mov    bx,word ptr addr
  134.         add    bx,0eh
  135.         mov    ax,word ptr ds:[bx]    ; Sectors before FAT
  136.         add    bx,2
  137.         mov    cl,byte ptr ds:[bx]    ; Number of the FAT
  138.         dec    cl
  139.         add    bx,6
  140.         mov    dx,word ptr ds:[bx]    ; Number of sectors in one FAT
  141.         shl    dx,cl        ; Number of sectors in both FAT
  142.         add    ax,dx        ; Number of sectors before root
  143.         mov    startsector,ax
  144.         sub    bx,5
  145.         mov    dx,word ptr ds:[bx] ; Maximum root directory entries
  146.         mov    cl,4
  147.         shr    dx,cl        ; Root directory in sectors
  148.         inc    dx        ; dx*32/512+1
  149.         mov    bx,dx
  150.         mov    cl,5
  151.         shl    bx,cl        ; Root directory in bytes
  152.  
  153.         mov    ah,48h        ; Allocate memory
  154.         int    21h
  155.         jnc    @@get_root_010
  156.         jmp    @@get_root_err
  157.  
  158. @@get_root_010:    mov    addr1,ax
  159.         mov    ds,ax
  160.         mov    cx,dx
  161.         push    cx
  162.         mov    dx,startsector
  163.         mov    al,drive
  164.         xor    bx,bx
  165.         int    25h        ; Read root
  166.         pop    dx
  167.         pop    cx
  168.         jnc    @@get_root_020
  169. ; Disk is larger than 32 Mbytes.
  170.         mov    ax,startsector
  171.         mov    word ptr i25startsec,ax
  172.         mov    word ptr i25startsec+2,0
  173.         mov    i25countsec,cx
  174.         mov    i25off,0
  175.         mov    i25seg,ds
  176.         mov    al,drive
  177.         mov    cx,0ffffh
  178.         push    cs
  179.         pop    ds
  180.         lea    bx,i25startsec
  181.         int    25h
  182.         pop    dx
  183.         jc    @@get_root_err
  184. @@get_root_020:    xor    ax,ax
  185.         mov    bx,addr1
  186.         ret
  187. @@get_root_err:    mov    ax,-1
  188.         ret
  189. get_root    ENDP
  190.  
  191.  
  192.         END
  193.